﻿using System;
using Unis.Framework.Core.Exceptions;
using Unis.Framework.Core.Log;

namespace KingRoad.EPM.Web.Areas.PersonnelLog.PersonnelLogFramework.Common
{
    /// <summary>
    /// 系统异常信息记录
    /// </summary>
    public class TraceException
    {
        /// <summary>
        /// 记录错误信息
        /// </summary>
        /// <param name="ex">异常对象</param>
        public static void TraceMsgLog(Exception ex)
        {
            string msg = "";

            if (ex != null)
            {
                msg = "系统错误:" + ex.Message;
                if (ex.InnerException != null)
                {
                    msg += "内部错误:" + ex.InnerException.Message;
                    if (ex.InnerException.InnerException != null)
                        msg += "详细错误:" + ex.InnerException.InnerException.Message;
                    msg += "\n内部堆栈追踪:" + ex.StackTrace;

                }
                msg += "\n外部堆栈追踪:" + ex.StackTrace;
            }

            TraceEx.Write(msg, APPMessageType.SysErrInfo);
        }
        /// <summary>
        /// 记录一般错误
        /// </summary>
        /// <param name="str"></param>
        public static void TraceMsgLog(string str)
        {
            str.Replace(";", "\r\n");
            TraceEx.Write(str, APPMessageType.SysErrInfo);
        }
    }
}
